package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.InstitutionAddDTO;
import org.jsola.hr.dto.InstitutionUpdateDTO;
import org.jsola.hr.entity.InstitutionDO;
import org.jsola.hr.query.InstitutionQuery;
import org.jsola.hr.service.IInstitutionService;
import org.jsola.hr.vo.InstitutionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 制度
 *
 * @author zhr
 */
@Component
public class InstitutionTestHelper extends BaseTestHelper {
    
    @Autowired
    private IInstitutionService institutionService;

    /**
     * 生成add测试数据
     * @return InstitutionAddDTO
     */
    public InstitutionAddDTO getInstitutionAddDTO(){
        InstitutionAddDTO institutionAddDTO = new InstitutionAddDTO();
        institutionAddDTO.setInstitutionTypeId(getRandomValue("varchar",32));
        institutionAddDTO.setInstitutionTitle(getRandomValue("varchar",32));
        institutionAddDTO.setInstitutionUrl(getRandomValue("text",2147483647));
        institutionAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        institutionAddDTO.setInstitutionContent(getRandomValue("text",2147483647));
        institutionAddDTO.setPlainText(getRandomValue("text",2147483647));
        institutionAddDTO.setCompanyId(getRandomValue("varchar",32));
        return institutionAddDTO;
    }


    /**
     * 生成update测试数据
     * @return InstitutionUpdateDTO
     */
    public InstitutionUpdateDTO getInstitutionUpdateDTO(InstitutionVO institutionVO){
        return institutionService.selectDOById(institutionVO.getId(), SITE_ID).to(InstitutionUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return InstitutionQuery
     */
    public InstitutionQuery getInstitutionQuery() {
        InstitutionQuery institutionQuery = new InstitutionQuery();
        List<InstitutionDO> institutionDOList = institutionService.list(new InstitutionDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(institutionDOList)) {
            InstitutionDO institutionDO = institutionDOList.get(0);
            institutionQuery = institutionDO.to(InstitutionQuery.class);
        }
        return institutionQuery;
    }

    /**
     * 保存示例
     * @return InstitutionVO
     */
    public InstitutionVO saveInstitutionExample(){
        InstitutionAddDTO addDTO = this.getInstitutionAddDTO();
        InstitutionVO institutionVO = institutionService.save(addDTO,buildTokenUser());
        return institutionVO;
    }


}

